<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../../layui-v2.4.3/layui/css/layui.css" media="all">
</head>
<body>
<div class="layui-container" style="margin-top: 30px;">
<table class="layui-hide" id="test" lay-filter="test"></table>
</div>

<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="detail">查看详情</a>
</script>
          
<script src="../../js/jquery.js"></script>
<script src="../../layui-v2.4.3/layui/layui.js"></script>
<script src="../../js/jquery.cookie.js"></script>

<script type="text/html" id="toolbarDemo">
	<div class="layui-inline">
		<select name="condition" id="queryCondition">
			<option value="1">班级</option>
			<option value="2">年级</option>
			<option value="3">试验名称</option>
		</select>     
	</div>
	<div class="layui-inline">
    <input class="layui-input" id="queryContext">
  </div>
  <div class="layui-inline">
  	<button class="layui-btn" lay-event="isAll">搜索</button>
  </div>
</script>

<script>
layui.use('table', function(){
  var table = layui.table;
  var con = {"context":"","condition":""}
  table.render({
  	id: 'studentScore'
    ,elem: '#test'
    ,toolbar: '#toolbarDemo'
    ,height: 500
    ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
      layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
      ,groups: 1 //只显示 1 个连续页码
      ,limits:[10, 20, 30, 40, 50]
    }
    ,url: 'http://localhost:8080/teacher/exp/getInfo.do'
    ,where: { 
    	uid: $.cookie("uid"),
    } 
    ,page: true //开启分页 
    ,cols: [[ //表头 
      {field: 'claGrade', title: '年级', sort: true}
      ,{field: 'claName', title: '班级名称', sort: true}
      ,{field: 'expName', title: '试验名称', sort: true}
      ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
    ]]
  });  
  
  
  
    table.on('toolbar(test)', function(obj){
    var checkStatus = table.checkStatus(obj.config.id);
    switch(obj.event){
      case 'isAll':
      	con.condition = $("#queryCondition").val();
      	con.context = $("#queryContext").val();

				table.reload('studentScore',{
       		where:{
						uid: $.cookie("uid"),
			    	condition: $("#queryCondition").val(),
			    	context : $("#queryContext").val(),
        	},
        	page: {
          	curr: 1,
        	}
        });
      break;
    };
  });
  
  
    //监听行工具事件
  table.on('tool(test)', function(obj){
    var data = obj.data;
    //console.log(obj)
    if(obj.event === 'detail'){
    	layer.msg(data.claId +','+data.expId);
    	window.location.href = "calculateScore.html?claId="+data.claId+"&expId="+data.expId;
    }
  });
}); 
</script>

</body>
</html>